<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".multiselect").multiselect({height: 260, minWidth: 160});
	$(".symbol_click").click(function(){
		$(this).hide();
		$(this).next().show();
		$(this).next().focus();
	});
	$(".symbol_select").blur(function(){
		var current_tag = $(this);
		var order_id = $(this).next().next().val();
		var old_postage_currency_id = $(this).prev().text();
		var new_postage_currency_id = $(this).val();
		if (old_postage_currency_id != new_postage_currency_id)
		{
			$.ajax({
				url: "<?=url('Finance::Business/ShippingFeeSave')?>&order_id=" + order_id + "&postage_currency_id=" + new_postage_currency_id,
				type: "GET",
				dataType: "text",
				success:
					function(data)
					{
						current_tag.prev().text(data);
					}
			});
		}
		$(this).hide();
		$(this).prev().show();
	});
	var old_shipping_fee;
	$(".blur").keypress(function(event){
		if (event.which == 13)
		{
			$(this).blur();
		}
	});
	$(".blur").focus(function(){
		$(this).removeClass("blur");
		old_shipping_fee = $(this).val();
	}).blur(function(){
		var current_tag = $(this);
		var order_id = $(this).next().val();
		var new_shipping_fee = $(this).val();
		if (new_shipping_fee != old_shipping_fee)
		{
			$.ajax({
				url: "<?=url('Finance::Business/ShippingFeeSave')?>&order_id=" + order_id + "&shipping_fee=" + new_shipping_fee,
				type: "GET",
				dataType: "json",
				success:
					function(data)
					{
						current_tag.addClass("blur");
					}
			});
		}
		else
		{
			current_tag.addClass("blur");
		}
	});
});
</script>
<style>
.blur {
	cursor: pointer;
	border: none;
}
</style>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table" width="100%">
<tr>
	<th width="60">发货日期</th>
	<td>
		<input type="text" name="begin_shipped_time" class="datepicker" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : ''?>" /> to
		<input type="text" name="end_shipped_time" class="datepicker" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>网站/店铺</th>
	<td>
		<select name="shop_id[]" multiple="multiple" class="multiselect">
		<?foreach ($shop_group as $k => $sg):?>
		<optgroup label="<?=$k?>">
		<?foreach ($sg as $s):?>
		<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && is_array($_GET['shop_id']) && in_array($s['id'], $_GET['shop_id'])) echo "selected='selected'"?>><?=$s['name']?></option>
		<?endforeach;?>
		</optgroup>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id[]" multiple="multiple" class="multiselect">
		<?foreach ($warehouse_group as $k => $sg):?>
		<optgroup label="<?=$k?>">
		<?foreach ($sg as $s):?>
		<option value="<?=$s['id']?>" <?if (isset($_GET['warehouse_id']) && is_array($_GET['warehouse_id']) && in_array($s['id'], $_GET['warehouse_id']))echo "selected='selected'";elseif (isset($_GET['warehouse_id']) && $_GET['warehouse_id'] == $s['id'])echo "selected='selected'"?>><?=$s['name']?></option>
		<?endforeach;?>
		</optgroup>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>本地单号</th>
	<td><input type="text" name="number" value="<?=isset($_GET['number']) ? $_GET['number'] : ''?>" /></td>
</tr>
<tr>
	<th>物流订单号</th>
	<td><input type="text" name="lsp_number" value="<?=isset($_GET['lsp_number']) ? $_GET['lsp_number'] : ''?>" /></td>
</tr>
<tr>
	<th>物流包裹号</th>
	<td><input type="text" name="tracking_number" value="<?=isset($_GET['tracking_number']) ? $_GET['tracking_number'] : ''?>" /></td>
</tr>
<tr>
	<th>邮寄方式</th>
	<td colspan="3">
		<table>
		<?foreach ($shipping_method as $sm):?>
		<tr>
			<th><strong><?=$sm['name']?>：</strong></th>
			<td style="padding: 1px;">
				<?foreach ($sm['children'] as $v):?>
				<label style="float: left;"><input type="checkbox" name="shipping_method[<?=$v['id']?>]" value="<?=$v['id']?>" <?if (isset($_GET['shipping_method']) && array_key_exists($v['id'], $_GET['shipping_method'])) echo "checked='checked'"?> /> <?=$v['name']?>&nbsp;</label>
				<?endforeach;?>
			</td>
		</tr>
		<?endforeach;?>
		</table>
	</td>
</tr>
<tr>
	<th><input type="hidden" name="is_search" value="1" /> </th>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<?if (isset($sales_order)):?>
<table width="100%" class="list_table">
<tr>
	<th width="80">本地单号</th>
	<th>网站</th>
	<th width="130">发货时间</th>
	<th width="150">物流订单号</th>
	<th width="150">物流包裹号</th>
	<th width="80">邮寄方式</th>
	<th width="80">重量</th>
	<th width="110">物流费用</th>
</tr>
<?foreach ($sales_order as $so):?>
<tr>
	<td><?=$so['number']?></td>
	<td><?=$so['shop_name']?></td>
	<td><?=$so['shipped_time']?></td>
	<td><?=$so['lsp_number']?></td>
	<td><?=$so['tracking_number']?></td>
	<td><?=$so['shipping_method_name']?></td>
	<td><?=sprintf('%.2f', $so['weight'])?>g</td>
	<td>
		<span style="padding-left: 20px" class="symbol_click"><?=$so['postage_currency_symbol']?></span><select name="" class="symbol_select" style="float: left; display: none;">
			<?foreach ($currency as $c):?>
			<option value="<?=$c['id']?>" <?=$c['id'] == $so['postage_currency_symbol'] ? 'selected="selected"' : ''?>><?=$c['code']?></option>
			<?endforeach;?>
		</select><input type="text" class="blur" value="<?=sprintf('%.2f', $so['postage'])?>" size="5" />
		<input type="hidden" value="<?=$so['id']?>" />
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<th>导出</th>
	<td>
		<a href="<?=url('Finance::Business/ShippingFeeExport', array('url_arr' => $url_arr))?>">
		<input type="button" value="运费单" class="button send_create" id="export_search_btn" />
		</a>
	</td>
	</tr>
</table>
<?if (isset($postage)):?>
<?$weight = $postage_amount_cny = 0;?>
<?$postage_amount = array();?>
<?foreach ($postage as $p):?>
<?$weight += $p['weight'];?>
<?$postage_amount_cny += $p['postage_amount_cny'];?>
<?$postage_amount[] = '<strong>' . $p['code'] . '：</strong>' . (isset($p['postage_amount']) ? sprintf('%.2f', $p['postage_amount']) : '0.00');?>
<?endforeach;?>
搜索条件总重量：<strong><?=sprintf('%.2f', $weight)?> g</strong><br />
搜索条件总物流费用：<?=implode(' + ', $postage_amount) . ' = <strong>CNY：</strong>' . sprintf('%.2f', $postage_amount_cny);?>
<?endif;?>
<?endif;?>
<?php $this->_endblock();?>